package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.admin.service.DictItemService;
import com.yugao.fintech.draper.admin.param.DictItemDTO;
import com.yugao.fintech.draper.datasource.entity.PageResult;
import com.yugao.fintech.draper.admin.param.DictItemExistsDTO;
import com.yugao.fintech.draper.admin.param.DictItemQuery;
import com.yugao.fintech.draper.core.model.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictItem")
@RequiredArgsConstructor
@Tag(name = "系统字典项管理")
public class DictItemController {
	private final DictItemService dictItemService;

	@Operation(summary = "查询字典项列表分页")
	@GetMapping("/page")
	public ResultVO<PageResult<DictItemDTO>> pageQuery(@RequestBody DictItemQuery dictItemQuery) {
		return ResultVO.success(PageResult.success(dictItemService.pageQuery(dictItemQuery)));
	}

	@Operation(summary = "添加字典项")
	@PostMapping(value = "/add")
	public ResultVO<Boolean> add(@RequestBody DictItemDTO dictItemDTO) {
		return ResultVO.success(dictItemService.addDictItem(dictItemDTO));
	}

	@Operation(summary = "修改字典项")
	@PostMapping(value = "/update")
	public ResultVO<Boolean> update(@RequestBody DictItemDTO dictItemDTO) {
		return ResultVO.success(dictItemService.updateDictItem(dictItemDTO));
	}

	@Operation(summary = "删除字典项")
	@DeleteMapping(value = "/delete")
	public ResultVO<Boolean> delete(Long id) {
		return ResultVO.success(dictItemService.deleteDictItem(id));
	}

	@Operation(summary = "查看全部字典项")
	@GetMapping(value = "/findAll")
	public ResultVO<List<DictItemDTO>> findAll() {
		return ResultVO.success(dictItemService.findAll());
	}

	@Operation(summary = "获取字典项详细信息")
	@GetMapping(value = "/findById")
	public ResultVO<DictItemDTO> findById(Long id) {
		return ResultVO.success(dictItemService.findById(id));
	}

	@Operation(summary = "校验字典项编码是否已经被使用")
	@GetMapping("/itemExistsByCode")
	public ResultVO<Boolean> itemExistsByCode(DictItemExistsDTO dictItemExistsDTO) {
		return ResultVO.success(dictItemService.itemExistsByCode(dictItemExistsDTO));
	}
}